<?php
session_start();
/*
 * O'My Friends
 * index.php
 * show friends' ranking
 */
$lib_dir = dirname(__FILE__).'/lib/';
require_once $lib_dir.'config.php';
//require_once $lib_dir.'facebook.php';
require_once $lib_dir.'util.php';
//require_once $lib_dir.'friend.php';
//require_once $lib_dir.'friends.php';
require_once $lib_dir.'view.php';


//Test data
$json1 = '[{"fId" : "612139051","name" : "Kerry Marie Millerick","score" : "130"},{"fId" : "509836156","name" : "Laurence Cliff","score" : "113"},{"fId" : "1559108118","name" : "Anastasios Thanopoulos","score" : "76"},{"fId" : "1452136143","name" : "Sarah Bak","score" : "62"},{"fId" : "100000525262538","name" : "Jaesun Park","score" : "43"},{"fId" : "711806955","name" : "Arkadiusz Lendzian","score" : "37"},{"fId" : "1382591304","name" : "Gopi Krishna C P","score" : "25"},{"fId" : "100000767659366","name" : "Jooyeon Kim","score" : "23"},{"fId" : "645061280","name" : "TaeYoung Ahn","score" : "20"},{"fId" : "100000416787478","name" : "Yool Park","score" : "18"},{"fId" : "550118413","name" : "Stef Gre","score" : "18"},{"fId" : "100000526102422","name" : "SangMi Aureliae Choe","score" : "16"},{"fId" : "1468604886","name" : "Lim Sungchol","score" : "16"},{"fId" : "100000560912448","name" : "Sanghee Park","score" : "13"},{"fId" : "1356805212","name" : "Philippe Coulon","score" : "10"},{"fId" : "100001496104711","name" : "Jaeho Chung","score" : "10"},{"fId" : "1676325929","name" : "Iktae Sohn","score" : "10"},{"fId" : "572356495","name" : "Jaeeun Chung","score" : "10"},{"fId" : "720480184","name" : "Hitesh Mohabeer","score" : "9"},{"fId" : "100000293254433","name" : "Kevin Hong","score" : "9"},{"fId" : "100000568852321","name" : "Bum-Jo Kim","score" : "8"},{"fId" : "15720738","name" : "Kyounghee Kwon","score" : "8"},{"fId" : "555926326","name" : "Adam Coulson","score" : "8"},{"fId" : "1128757552","name" : "Oh Sei Hoon Dan","score" : "8"},{"fId" : "1847145997","name" : "Sang Joon Hong","score" : "7"},{"fId" : "1637340897","name" : "Mj Park","score" : "7"},{"fId" : "732486215","name" : "Anne Lee","score" : "7"},{"fId" : "1185268272","name" : "Jung Han Woo","score" : "5"},{"fId" : "100001437546761","name" : "장원익","score" : "5"},{"fId" : "612484233","name" : "Moon Myung Hyo","score" : "5"},{"fId" : "100001297801606","name" : "Hyunmin Cho","score" : "4"},{"fId" : "100000545529457","name" : "Jeongyeol Kwak","score" : "4"},{"fId" : "520468704","name" : "Heejin Kim","score" : "4"},{"fId" : "100001753717079","name" : "Donghyun Lee","score" : "4"},{"fId" : "534124579","name" : "Chungshik Moon","score" : "3"},{"fId" : "100000591117659","name" : "박재환","score" : "3"},{"fId" : "100001057185849","name" : "Hee Seung Lee","score" : "3"},{"fId" : "100001442696712","name" : "Ho Im Lee","score" : "3"},{"fId" : "100001623437056","name" : "Hyunju Kim","score" : "3"},{"fId" : "1547370475","name" : "Thai-ngoc Duong","score" : "3"},{"fId" : "100001562863238","name" : "Kyungjong Jung","score" : "2"},{"fId" : "100001875630715","name" : "Minyoung Jeong","score" : "2"},{"fId" : "100001871979183","name" : "Min Gyu Lee","score" : "0"},{"fId" : "100001041562777","name" : "Youngwook Kang","score" : "0"},{"fId" : "100001794018281","name" : "Hee Kyong Kim","score" : "0"},{"fId" : "100001660120678","name" : "Sang Chul Kim","score" : "0"},{"fId" : "100001474516590","name" : "Kwang Hyun Park","score" : "0"},{"fId" : "100001573101794","name" : "Jeongkwon Park","score" : "0"},{"fId" : "100001616612326","name" : "Jinsang Hwang","score" : "0"},{"fId" : "100001324002549","name" : "Hyanghee Lee","score" : "0"},{"fId" : "1617980445","name" : "신동훈","score" : "0"},{"fId" : "765455726","name" : "Minji Kim","score" : "0"},{"fId" : "855739608","name" : "WY Paik","score" : "0"},{"fId" : "1281934594","name" : "Seung-woo Lee","score" : "0"},{"fId" : "639171815","name" : "Su Jin Hong","score" : "0"},{"fId" : "573168545","name" : "조호석","score" : "0"},{"fId" : "502925698","name" : "Lunamoth Yun","score" : "0"},{"fId" : "509400009","name" : "Alexandra Wingate","score" : "0"},{"fId" : "542016885","name" : "Jongwoo Nam","score" : "0"},{"fId" : "1379851573","name" : "Yohan Lee","score" : "0"},{"fId" : "1436029649","name" : "Bindu Keerthy","score" : "0"},{"fId" : "100000243514929","name" : "강상현","score" : "0"},{"fId" : "100000550522019","name" : "Onesixx Chung","score" : "0"},{"fId" : "100000571402532","name" : "박준상","score" : "0"},{"fId" : "100000036440363","name" : "Dawoon Han","score" : "0"},{"fId" : "1535994324","name" : "Youn Jin Choi","score" : "0"},{"fId" : "1481610536","name" : "Jinhan Kim","score" : "0"},{"fId" : "1535926803","name" : "Lee MacBain","score" : "0"},{"fId" : "100000633970805","name" : "Jeongkyu Shin","score" : "0"}]';
$json2 = '[{"id1" : "15720738","id2" : "572356495"},{"id1" : "15720738","id2" : "1452136143"},{"id1" : "15720738","id2" : "1676325929"},{"id1" : "502925698","id2" : "100000633970805"},{"id1" : "509400009","id2" : "509836156"},{"id1" : "509400009","id2" : "100001041562777"},{"id1" : "509836156","id2" : "509400009"},{"id1" : "509836156","id2" : "550118413"},{"id1" : "509836156","id2" : "555926326"},{"id1" : "509836156","id2" : "612139051"},{"id1" : "509836156","id2" : "711806955"},{"id1" : "509836156","id2" : "1535926803"},{"id1" : "509836156","id2" : "1559108118"},{"id1" : "520468704","id2" : "100001297801606"},{"id1" : "534124579","id2" : "572356495"},{"id1" : "534124579","id2" : "1281934594"},{"id1" : "534124579","id2" : "1379851573"},{"id1" : "534124579","id2" : "1676325929"},{"id1" : "534124579","id2" : "100000526102422"},{"id1" : "534124579","id2" : "100001057185849"},{"id1" : "534124579","id2" : "100001437546761"},{"id1" : "542016885","id2" : "572356495"},{"id1" : "550118413","id2" : "509836156"},{"id1" : "550118413","id2" : "555926326"},{"id1" : "550118413","id2" : "612139051"},{"id1" : "550118413","id2" : "711806955"},{"id1" : "555926326","id2" : "509836156"},{"id1" : "555926326","id2" : "550118413"},{"id1" : "555926326","id2" : "711806955"},{"id1" : "555926326","id2" : "720480184"},{"id1" : "572356495","id2" : "15720738"},{"id1" : "572356495","id2" : "534124579"},{"id1" : "572356495","id2" : "542016885"},{"id1" : "572356495","id2" : "732486215"},{"id1" : "572356495","id2" : "1128757552"},{"id1" : "572356495","id2" : "1379851573"},{"id1" : "572356495","id2" : "1452136143"},{"id1" : "572356495","id2" : "1676325929"},{"id1" : "572356495","id2" : "100000243514929"},{"id1" : "572356495","id2" : "100000416787478"},{"id1" : "572356495","id2" : "100000525262538"},{"id1" : "572356495","id2" : "100000526102422"},{"id1" : "572356495","id2" : "100000568852321"},{"id1" : "572356495","id2" : "100001057185849"},{"id1" : "572356495","id2" : "100001437546761"},{"id1" : "573168545","id2" : "100001442696712"},{"id1" : "612139051","id2" : "509836156"},{"id1" : "612139051","id2" : "550118413"},{"id1" : "612139051","id2" : "711806955"},{"id1" : "612139051","id2" : "1382591304"},{"id1" : "612139051","id2" : "1436029649"},{"id1" : "612139051","id2" : "1535926803"},{"id1" : "612139051","id2" : "1559108118"},{"id1" : "612484233","id2" : "1356805212"},{"id1" : "612484233","id2" : "1637340897"},{"id1" : "711806955","id2" : "509836156"},{"id1" : "711806955","id2" : "550118413"},{"id1" : "711806955","id2" : "555926326"},{"id1" : "711806955","id2" : "612139051"},{"id1" : "711806955","id2" : "720480184"},{"id1" : "711806955","id2" : "1535926803"},{"id1" : "711806955","id2" : "1559108118"},{"id1" : "720480184","id2" : "555926326"},{"id1" : "720480184","id2" : "711806955"},{"id1" : "720480184","id2" : "1382591304"},{"id1" : "720480184","id2" : "1535926803"},{"id1" : "732486215","id2" : "572356495"},{"id1" : "732486215","id2" : "1185268272"},{"id1" : "732486215","id2" : "1452136143"},{"id1" : "732486215","id2" : "1676325929"},{"id1" : "732486215","id2" : "100000416787478"},{"id1" : "732486215","id2" : "100000525262538"},{"id1" : "732486215","id2" : "100000526102422"},{"id1" : "732486215","id2" : "100000568852321"},{"id1" : "732486215","id2" : "100001437546761"},{"id1" : "732486215","id2" : "100001474516590"},{"id1" : "765455726","id2" : "1356805212"},{"id1" : "765455726","id2" : "100000036440363"},{"id1" : "855739608","id2" : "1452136143"},{"id1" : "855739608","id2" : "100000525262538"},{"id1" : "855739608","id2" : "100000545529457"},{"id1" : "1128757552","id2" : "572356495"},{"id1" : "1128757552","id2" : "1185268272"},{"id1" : "1128757552","id2" : "1379851573"},{"id1" : "1128757552","id2" : "1617980445"},{"id1" : "1128757552","id2" : "100000525262538"},{"id1" : "1128757552","id2" : "100000526102422"},{"id1" : "1128757552","id2" : "100000571402532"},{"id1" : "1128757552","id2" : "100001474516590"},{"id1" : "1185268272","id2" : "732486215"},{"id1" : "1185268272","id2" : "1128757552"},{"id1" : "1185268272","id2" : "1617980445"},{"id1" : "1185268272","id2" : "100000416787478"},{"id1" : "1185268272","id2" : "100000525262538"},{"id1" : "1185268272","id2" : "100000526102422"},{"id1" : "1185268272","id2" : "100000568852321"},{"id1" : "1185268272","id2" : "100000571402532"},{"id1" : "1185268272","id2" : "100001474516590"},{"id1" : "1281934594","id2" : "534124579"},{"id1" : "1281934594","id2" : "100001437546761"},{"id1" : "1356805212","id2" : "612484233"},{"id1" : "1356805212","id2" : "765455726"},{"id1" : "1356805212","id2" : "1637340897"},{"id1" : "1356805212","id2" : "100000036440363"},{"id1" : "1379851573","id2" : "534124579"},{"id1" : "1379851573","id2" : "572356495"},{"id1" : "1379851573","id2" : "1128757552"},{"id1" : "1379851573","id2" : "1676325929"},{"id1" : "1379851573","id2" : "100000525262538"},{"id1" : "1379851573","id2" : "100000526102422"},{"id1" : "1379851573","id2" : "100000560912448"},{"id1" : "1379851573","id2" : "100000568852321"},{"id1" : "1379851573","id2" : "100001057185849"},{"id1" : "1379851573","id2" : "100001437546761"},{"id1" : "1382591304","id2" : "612139051"},{"id1" : "1382591304","id2" : "720480184"},{"id1" : "1436029649","id2" : "612139051"},{"id1" : "1452136143","id2" : "15720738"},{"id1" : "1452136143","id2" : "572356495"},{"id1" : "1452136143","id2" : "732486215"},{"id1" : "1452136143","id2" : "855739608"},{"id1" : "1452136143","id2" : "100000416787478"},{"id1" : "1452136143","id2" : "100000525262538"},{"id1" : "1452136143","id2" : "100000526102422"},{"id1" : "1452136143","id2" : "100000568852321"},{"id1" : "1452136143","id2" : "100000767659366"},{"id1" : "1452136143","id2" : "100001437546761"},{"id1" : "1452136143","id2" : "100001474516590"},{"id1" : "1468604886","id2" : "100000293254433"},{"id1" : "1468604886","id2" : "100000416787478"},{"id1" : "1481610536","id2" : "100000293254433"},{"id1" : "1481610536","id2" : "100000416787478"},{"id1" : "1535926803","id2" : "509836156"},{"id1" : "1535926803","id2" : "612139051"},{"id1" : "1535926803","id2" : "711806955"},{"id1" : "1535926803","id2" : "720480184"},{"id1" : "1535926803","id2" : "1559108118"},{"id1" : "1535994324","id2" : "100000293254433"},{"id1" : "1535994324","id2" : "100000416787478"},{"id1" : "1559108118","id2" : "509836156"},{"id1" : "1559108118","id2" : "612139051"},{"id1" : "1559108118","id2" : "711806955"},{"id1" : "1559108118","id2" : "1535926803"},{"id1" : "1617980445","id2" : "1128757552"},{"id1" : "1617980445","id2" : "1185268272"},{"id1" : "1617980445","id2" : "100000525262538"},{"id1" : "1617980445","id2" : "100000571402532"},{"id1" : "1617980445","id2" : "100001474516590"},{"id1" : "1637340897","id2" : "612484233"},{"id1" : "1637340897","id2" : "1356805212"},{"id1" : "1676325929","id2" : "15720738"},{"id1" : "1676325929","id2" : "534124579"},{"id1" : "1676325929","id2" : "572356495"},{"id1" : "1676325929","id2" : "732486215"},{"id1" : "1676325929","id2" : "1379851573"},{"id1" : "1676325929","id2" : "100000416787478"},{"id1" : "1676325929","id2" : "100000525262538"},{"id1" : "1676325929","id2" : "100000526102422"},{"id1" : "1676325929","id2" : "100000560912448"},{"id1" : "1676325929","id2" : "100000568852321"},{"id1" : "1676325929","id2" : "100001057185849"},{"id1" : "1676325929","id2" : "100001437546761"},{"id1" : "1676325929","id2" : "100001474516590"},{"id1" : "100000036440363","id2" : "765455726"},{"id1" : "100000036440363","id2" : "1356805212"},{"id1" : "100000243514929","id2" : "572356495"},{"id1" : "100000243514929","id2" : "100001297801606"},{"id1" : "100000293254433","id2" : "1468604886"},{"id1" : "100000293254433","id2" : "1481610536"},{"id1" : "100000293254433","id2" : "1535994324"},{"id1" : "100000416787478","id2" : "572356495"},{"id1" : "100000416787478","id2" : "732486215"},{"id1" : "100000416787478","id2" : "1185268272"},{"id1" : "100000416787478","id2" : "1452136143"},{"id1" : "100000416787478","id2" : "1468604886"},{"id1" : "100000416787478","id2" : "1481610536"},{"id1" : "100000416787478","id2" : "1535994324"},{"id1" : "100000416787478","id2" : "1676325929"},{"id1" : "100000416787478","id2" : "100000525262538"},{"id1" : "100000416787478","id2" : "100000526102422"},{"id1" : "100000416787478","id2" : "100000545529457"},{"id1" : "100000416787478","id2" : "100000560912448"},{"id1" : "100000416787478","id2" : "100000568852321"},{"id1" : "100000416787478","id2" : "100000571402532"},{"id1" : "100000416787478","id2" : "100000767659366"},{"id1" : "100000416787478","id2" : "100001041562777"},{"id1" : "100000416787478","id2" : "100001057185849"},{"id1" : "100000416787478","id2" : "100001437546761"},{"id1" : "100000416787478","id2" : "100001474516590"},{"id1" : "100000416787478","id2" : "100001496104711"},{"id1" : "100000416787478","id2" : "100001573101794"},{"id1" : "100000416787478","id2" : "100001623437056"},{"id1" : "100000525262538","id2" : "572356495"},{"id1" : "100000525262538","id2" : "732486215"},{"id1" : "100000525262538","id2" : "855739608"},{"id1" : "100000525262538","id2" : "1128757552"},{"id1" : "100000525262538","id2" : "1185268272"},{"id1" : "100000525262538","id2" : "1379851573"},{"id1" : "100000525262538","id2" : "1452136143"},{"id1" : "100000525262538","id2" : "1617980445"},{"id1" : "100000525262538","id2" : "1676325929"},{"id1" : "100000525262538","id2" : "100000416787478"},{"id1" : "100000525262538","id2" : "100000526102422"},{"id1" : "100000525262538","id2" : "100000560912448"},{"id1" : "100000525262538","id2" : "100000568852321"},{"id1" : "100000525262538","id2" : "100000571402532"},{"id1" : "100000525262538","id2" : "100000767659366"},{"id1" : "100000525262538","id2" : "100001057185849"},{"id1" : "100000525262538","id2" : "100001437546761"},{"id1" : "100000525262538","id2" : "100001474516590"},{"id1" : "100000526102422","id2" : "534124579"},{"id1" : "100000526102422","id2" : "572356495"},{"id1" : "100000526102422","id2" : "732486215"},{"id1" : "100000526102422","id2" : "1128757552"},{"id1" : "100000526102422","id2" : "1185268272"},{"id1" : "100000526102422","id2" : "1379851573"},{"id1" : "100000526102422","id2" : "1452136143"},{"id1" : "100000526102422","id2" : "1676325929"},{"id1" : "100000526102422","id2" : "100000416787478"},{"id1" : "100000526102422","id2" : "100000525262538"},{"id1" : "100000526102422","id2" : "100000568852321"},{"id1" : "100000526102422","id2" : "100000767659366"},{"id1" : "100000526102422","id2" : "100001437546761"},{"id1" : "100000526102422","id2" : "100001474516590"},{"id1" : "100000545529457","id2" : "855739608"},{"id1" : "100000545529457","id2" : "100000416787478"},{"id1" : "100000550522019","id2" : "100000591117659"},{"id1" : "100000560912448","id2" : "1379851573"},{"id1" : "100000560912448","id2" : "1676325929"},{"id1" : "100000560912448","id2" : "100000416787478"},{"id1" : "100000560912448","id2" : "100000525262538"},{"id1" : "100000560912448","id2" : "100000568852321"},{"id1" : "100000560912448","id2" : "100001057185849"},{"id1" : "100000560912448","id2" : "100001437546761"},{"id1" : "100000568852321","id2" : "572356495"},{"id1" : "100000568852321","id2" : "732486215"},{"id1" : "100000568852321","id2" : "1185268272"},{"id1" : "100000568852321","id2" : "1379851573"},{"id1" : "100000568852321","id2" : "1452136143"},{"id1" : "100000568852321","id2" : "1676325929"},{"id1" : "100000568852321","id2" : "100000416787478"},{"id1" : "100000568852321","id2" : "100000525262538"},{"id1" : "100000568852321","id2" : "100000526102422"},{"id1" : "100000568852321","id2" : "100000560912448"},{"id1" : "100000568852321","id2" : "100000571402532"},{"id1" : "100000568852321","id2" : "100000767659366"},{"id1" : "100000568852321","id2" : "100001057185849"},{"id1" : "100000568852321","id2" : "100001437546761"},{"id1" : "100000571402532","id2" : "1128757552"},{"id1" : "100000571402532","id2" : "1185268272"},{"id1" : "100000571402532","id2" : "1617980445"},{"id1" : "100000571402532","id2" : "100000416787478"},{"id1" : "100000571402532","id2" : "100000525262538"},{"id1" : "100000571402532","id2" : "100000568852321"},{"id1" : "100000571402532","id2" : "100001437546761"},{"id1" : "100000571402532","id2" : "100001474516590"},{"id1" : "100000591117659","id2" : "100000550522019"},{"id1" : "100000591117659","id2" : "100001660120678"},{"id1" : "100000633970805","id2" : "502925698"},{"id1" : "100000767659366","id2" : "1452136143"},{"id1" : "100000767659366","id2" : "100000416787478"},{"id1" : "100000767659366","id2" : "100000525262538"},{"id1" : "100000767659366","id2" : "100000526102422"},{"id1" : "100000767659366","id2" : "100000568852321"},{"id1" : "100000767659366","id2" : "100001437546761"},{"id1" : "100000767659366","id2" : "100001474516590"},{"id1" : "100000767659366","id2" : "100001794018281"},{"id1" : "100001041562777","id2" : "509400009"},{"id1" : "100001041562777","id2" : "100000416787478"},{"id1" : "100001057185849","id2" : "534124579"},{"id1" : "100001057185849","id2" : "572356495"},{"id1" : "100001057185849","id2" : "1379851573"},{"id1" : "100001057185849","id2" : "1676325929"},{"id1" : "100001057185849","id2" : "100000416787478"},{"id1" : "100001057185849","id2" : "100000525262538"},{"id1" : "100001057185849","id2" : "100000560912448"},{"id1" : "100001057185849","id2" : "100000568852321"},{"id1" : "100001057185849","id2" : "100001437546761"},{"id1" : "100001057185849","id2" : "100001474516590"},{"id1" : "100001297801606","id2" : "520468704"},{"id1" : "100001297801606","id2" : "100000243514929"},{"id1" : "100001437546761","id2" : "534124579"},{"id1" : "100001437546761","id2" : "572356495"},{"id1" : "100001437546761","id2" : "732486215"},{"id1" : "100001437546761","id2" : "1281934594"},{"id1" : "100001437546761","id2" : "1379851573"},{"id1" : "100001437546761","id2" : "1452136143"},{"id1" : "100001437546761","id2" : "1676325929"},{"id1" : "100001437546761","id2" : "100000416787478"},{"id1" : "100001437546761","id2" : "100000525262538"},{"id1" : "100001437546761","id2" : "100000526102422"},{"id1" : "100001437546761","id2" : "100000560912448"},{"id1" : "100001437546761","id2" : "100000568852321"},{"id1" : "100001437546761","id2" : "100000571402532"},{"id1" : "100001437546761","id2" : "100000767659366"},{"id1" : "100001437546761","id2" : "100001057185849"},{"id1" : "100001437546761","id2" : "100001474516590"},{"id1" : "100001442696712","id2" : "573168545"},{"id1" : "100001474516590","id2" : "732486215"},{"id1" : "100001474516590","id2" : "1128757552"},{"id1" : "100001474516590","id2" : "1185268272"},{"id1" : "100001474516590","id2" : "1452136143"},{"id1" : "100001474516590","id2" : "1617980445"},{"id1" : "100001474516590","id2" : "1676325929"},{"id1" : "100001474516590","id2" : "100000416787478"},{"id1" : "100001474516590","id2" : "100000525262538"},{"id1" : "100001474516590","id2" : "100000526102422"},{"id1" : "100001474516590","id2" : "100000571402532"},{"id1" : "100001474516590","id2" : "100000767659366"},{"id1" : "100001474516590","id2" : "100001057185849"},{"id1" : "100001474516590","id2" : "100001437546761"},{"id1" : "100001496104711","id2" : "100000416787478"},{"id1" : "100001496104711","id2" : "100001623437056"},{"id1" : "100001573101794","id2" : "100000416787478"},{"id1" : "100001623437056","id2" : "100000416787478"},{"id1" : "100001623437056","id2" : "100001496104711"},{"id1" : "100001660120678","id2" : "100000591117659"},{"id1" : "100001660120678","id2" : "100001875630715"},{"id1" : "100001794018281","id2" : "100000767659366"},{"id1" : "100001875630715","id2" : "100001660120678"}]';

$friends = json_decode($json1);
$fof = json_decode($json2);

//var_export($friends);
//var_export($fof);

/*
 * Build up output HTML
 */
//Get Template
$html = getTemplateHTML("Social Network Graph");
$appletHtml = file_get_contents('./applet/applet.html');

//Replace custom tag with a real value
$html = str_ireplace("[##_GRAPH_APPLET_##]", $appletHtml , $html);
$html = str_ireplace("[##_FRIENDS_##]", $json1, $html);
$html = str_ireplace("[##_FOF_##]", $json2, $html);

print $html;